<?php
class PictureBlock extends BlockInstance {
	public $CI;
	
	function __construct()
	{
		$this->CI =& get_instance();
	}
	
	function __call($m, $a)
	{
		global $BBX;
		if (preg_match('/[a-z]+_([a-z]+)/', $m, $matches))
		{
			$this->CI->load->model('Content_model');
			if ($matches[1] == 'content')
			{
				$content = $a[1];
				$data 	 = array(
					'block_instance' => $a[0],
					'bricabox'		 => $BBX['bricabox'],	// pass anyway so handle_proxy() can recreate the view via ajax
					'content'		 => $content			// pass anyway so handle_proxy() can recreate the view via ajax
				);
				$this->CI->load->view('blocks/picture/content', $data);
			}
			elseif ($matches[1] == 'homepage')
			{
				$_content = array();
				$_query   = $this->CI->db->query('select * from contents where bricabox_id = ? and data_file_upload <> "" and data_file_upload is not null', array($BBX['bricabox']->id));
				if ($_query->num_rows())
				{
					foreach ($_query->result() as $_c)
						if (preg_match('/\.(png|gif|jpg|jpeg)$/', strtolower($_c->data_file_upload)))
							$_content[] = $_c;
				}
				
				$data = array(
					'bricabox'		  => $BBX['bricabox'],
					'block_instance'  => $a[0],
					'picture_content' => $_content
				);
				$this->CI->load->view('blocks/picture/homepage', $data);
			}
		}
	}
}
?>